package cn.wolfcode.crm.service.impl;


import cn.wolfcode.crm.domain.DataItems;
import cn.wolfcode.crm.mapper.DataItemsMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDataItemsService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DataItemsServiceImpl implements IDataItemsService {
    @Autowired
    private DataItemsMapper mapper;
    public void save(DataItems entity) {
        mapper.insert(entity);
    }

    public void update(DataItems entity) {
        mapper.updateByPrimaryKey(entity);
    }

    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public List<DataItems> list() {
        return mapper.selectAll();
    }

    public DataItems get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public PageResult query(QueryObject qo) {

        //1:查总条数
        int total = mapper.queryForCount(qo);

        if(total == 0){
            return new PageResult();
        }
        //2:查分页数据
        List<DataItems> rows = mapper.queryForList(qo);

        return new PageResult(total, rows);
    }

    public List<DataItems> queryItemsBySn(String sn) {
        return mapper.queryItemsBySn(sn);
    }

    public String queryItemsByName(String name) {
        return mapper.queryItemsByName(name);
    }

}
